home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / include / CEGUI / elements / CEGUITooltip.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-07  |  11.9 KB  |  347 lines

  1. /************************************************************************
  2.     filename:   CEGUITooltip.h
  3.     created:    21/2/2005
  4.     author:     Paul D Turner
  5. *************************************************************************/
  6. /*************************************************************************
  7.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  8.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  9.  
  10.     This library is free software; you can redistribute it and/or
  11.     modify it under the terms of the GNU Lesser General Public
  12.     License as published by the Free Software Foundation; either
  13.     version 2.1 of the License, or (at your option) any later version.
  14.  
  15.     This library is distributed in the hope that it will be useful,
  16.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.     Lesser General Public License for more details.
  19.  
  20.     You should have received a copy of the GNU Lesser General Public
  21.     License along with this library; if not, write to the Free Software
  22.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23. *************************************************************************/
  24. #ifndef _CEGUITooltip_h_
  25. #define _CEGUITooltip_h_
  26.  
  27. #include "CEGUIWindow.h"
  28. #include "elements/CEGUITooltipProperties.h"
  29.  
  30. #if defined(_MSC_VER)
  31. #    pragma warning(push)
  32. #    pragma warning(disable : 4251)
  33. #endif
  34.  
  35. // Start of CEGUI namespace section
  36. namespace CEGUI
  37. {
  38.     class CEGUIEXPORT Tooltip : public Window
  39.     {
  40.     public:
  41.         /*************************************************************************
  42.             Constants
  43.         *************************************************************************/
  44.         static const String EventNamespace;                 //!< Namespace for global events
  45.         static const String EventHoverTimeChanged;          //!< Event fired when the hover timeout gets changed.
  46.         static const String EventDisplayTimeChanged;        //!< Event fired when the display timeout gets changed.
  47.         static const String EventFadeTimeChanged;           //!< Event fired when the fade timeout gets changed.
  48.         static const String EventTooltipActive;             //!< Event fired when the tooltip is about to get activated.
  49.         static const String EventTooltipInactive;           //!< Event fired when the tooltip has been deactivated.
  50.  
  51.         /************************************************************************
  52.             Object Construction and Destruction
  53.         ************************************************************************/
  54.         /*!
  55.         \brief
  56.             Constructor for the Tooltip base class constructor
  57.          */
  58.         Tooltip(const String& type, const String& name);
  59.  
  60.         /*!
  61.         \brief
  62.             Destructor for the Tooltip base class.
  63.          */
  64.         ~Tooltip(void);
  65.  
  66.         /************************************************************************
  67.             Public interface
  68.         ************************************************************************/
  69.         /*!
  70.         \brief
  71.             Sets the target window for the tooltip.  This used internally to manage tooltips, you
  72.             should not have to call this yourself.
  73.  
  74.         \param wnd
  75.             Window object that the tooltip should be associated with (for now).
  76.  
  77.         \return
  78.             Nothing.
  79.          */
  80.         void setTargetWindow(Window* wnd);
  81.  
  82.         /*!
  83.         \brief
  84.             return the current target window for this Tooltip.
  85.  
  86.         \return
  87.             Pointer to the target window for this Tooltip or 0 for none.
  88.         */
  89.         const Window* getTargetWindow();
  90.  
  91.         /*!
  92.         \brief
  93.             Resets the timer on the tooltip when in the Active / Inactive states.  This is used internally
  94.             to control the tooltip, it is not normally necessary to call this method yourself.
  95.  
  96.         \return
  97.             Nothing.
  98.          */
  99.         void resetTimer(void);
  100.  
  101.         /*!
  102.         \brief
  103.             Return the number of seconds the mouse should hover stationary over the target window before
  104.             the tooltip gets activated.
  105.  
  106.         \return
  107.             float value representing a number of seconds.
  108.          */
  109.         float getHoverTime(void) const;
  110.  
  111.         /*!
  112.         \brief
  113.             Set the number of seconds the tooltip should be displayed for before it automatically
  114.             de-activates itself.  0 indicates that the tooltip should never timesout and auto-deactivate.
  115.  
  116.         \param seconds
  117.             float value representing a number of seconds.
  118.  
  119.         \return
  120.             Nothing.
  121.          */
  122.         void setDisplayTime(float seconds);
  123.  
  124.         /*!
  125.         \brief
  126.             Return the number of seconds that should be taken to fade the tooltip into and out of
  127.             visibility.
  128.  
  129.         \return
  130.             float value representing a number of seconds.
  131.          */
  132.         float getFadeTime(void) const;
  133.  
  134.         /*!
  135.         \brief
  136.             Set the number of seconds the mouse should hover stationary over the target window before
  137.             the tooltip gets activated.
  138.  
  139.         \param seconds
  140.             float value representing a number of seconds.
  141.  
  142.         \return
  143.             Nothing.
  144.          */
  145.         void setHoverTime(float seconds);
  146.  
  147.         /*!
  148.         \brief
  149.             Return the number of seconds the tooltip should be displayed for before it automatically
  150.             de-activates itself.  0 indicates that the tooltip never timesout and auto-deactivates.
  151.  
  152.         \return
  153.             float value representing a number of seconds.
  154.          */
  155.         float getDisplayTime(void) const;
  156.  
  157.         /*!
  158.         \brief
  159.             Set the number of seconds that should be taken to fade the tooltip into and out of
  160.             visibility.
  161.  
  162.         \param seconds
  163.             float value representing a number of seconds.
  164.  
  165.         \return
  166.             Nothing.
  167.          */
  168.         void setFadeTime(float seconds);
  169.  
  170.         // 
  171.         /*!
  172.         \brief
  173.             Causes the tooltip to position itself appropriately.
  174.  
  175.         \return
  176.             Nothing.
  177.         */
  178.         void positionSelf(void);
  179.  
  180.     protected:
  181.         /*************************************************************************
  182.             Implementation Methods
  183.         *************************************************************************/
  184.         /*!
  185.         \brief
  186.             Add ScrollablePane specific events
  187.         */
  188.         void addTooltipEvents(void);
  189.  
  190.         // methods to perform processing for each of the widget states
  191.         void doActiveState(float elapsed);
  192.         void doInactiveState(float elapsed);
  193.         void doFadeInState(float elapsed);
  194.         void doFadeOutState(float elapsed);
  195.  
  196.         // methods to switch widget states
  197.         void switchToInactiveState(void);
  198.         void switchToActiveState(void);
  199.         void switchToFadeInState(void);
  200.         void switchToFadeOutState(void);
  201.  
  202.  
  203.         /*!
  204.         \brief
  205.             Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
  206.  
  207.         \param class_name
  208.             The class name that is to be checked.
  209.  
  210.         \return
  211.             true if this window was inherited from \a class_name. false if not.
  212.         */
  213.         virtual bool    testClassName_impl(const String& class_name) const
  214.         {
  215.             if (class_name==(const utf8*)"Tooltip")    return true;
  216.             return Window::testClassName_impl(class_name);
  217.         }
  218.  
  219.         /*!
  220.         \brief
  221.             Return the size of the area that will be occupied by the tooltip text, given
  222.             any current formatting options.
  223.  
  224.         \return
  225.             Size object describing the size of the rendered tooltip text in pixels.
  226.         */
  227.         virtual Size getTextSize() const;
  228.  
  229.         /*************************************************************************
  230.             Event triggers
  231.         *************************************************************************/
  232.         /*!
  233.         \brief
  234.             Event trigger method called when the hover timeout gets changed.
  235.  
  236.         \param e
  237.             WindowEventArgs object.
  238.  
  239.         \return
  240.             Nothing.
  241.         */
  242.         virtual void onHoverTimeChanged(WindowEventArgs& e);
  243.  
  244.         /*!
  245.         \brief
  246.             Event trigger method called when the display timeout gets changed.
  247.  
  248.         \param e
  249.             WindowEventArgs object.
  250.  
  251.         \return
  252.             Nothing.
  253.         */
  254.         virtual void onDisplayTimeChanged(WindowEventArgs& e);
  255.  
  256.         /*!
  257.         \brief
  258.             Event trigger method called when the fade timeout gets changed.
  259.  
  260.         \param e
  261.             WindowEventArgs object.
  262.  
  263.         \return
  264.             Nothing.
  265.         */
  266.         virtual void onFadeTimeChanged(WindowEventArgs& e);
  267.  
  268.         /*!
  269.         \brief
  270.             Event trigger method called just before the tooltip becomes active.
  271.  
  272.         \param e
  273.             WindowEventArgs object.
  274.  
  275.         \return
  276.             Nothing.
  277.         */
  278.         virtual void onTooltipActive(WindowEventArgs& e);
  279.  
  280.         /*!
  281.         \brief
  282.             Event trigger method called just after the tooltip is deactivated.
  283.  
  284.         \param e
  285.             WindowEventArgs object.
  286.  
  287.         \return
  288.             Nothing.
  289.         */
  290.         virtual void onTooltipInactive(WindowEventArgs& e);
  291.  
  292.  
  293.         /************************************************************************
  294.             Overridden from Window.
  295.         ************************************************************************/
  296.         void updateSelf(float elapsed);
  297.         void onMouseEnters(MouseEventArgs& e);
  298.         void onTextChanged(WindowEventArgs& e);
  299.  
  300.         /************************************************************************
  301.             Enumerations
  302.         ************************************************************************/
  303.         /*!
  304.         \brief
  305.             states for tooltip
  306.          */
  307.         enum TipState
  308.         {
  309.             Inactive,   //!< Tooltip is currently inactive.
  310.             Active,     //!< Tooltip is currently displayed and active.
  311.             FadeIn,     //!< Tooltip is currently transitioning from Inactive to Active state.
  312.             FadeOut     //!< Tooltip is currently transitioning from Active to Inactive state.
  313.         };
  314.  
  315.         /************************************************************************
  316.             Data fields
  317.         ************************************************************************/
  318.         TipState    d_state;        //!< Current tooltip state.
  319.         float       d_elapsed;      //!< Used to track state change timings
  320.         const Window* d_target;     //!< Current target Window for this Tooltip.
  321.         float       d_hoverTime;    //!< tool-tip hover time (seconds mouse must stay stationary before tip shows).
  322.         float       d_displayTime;  //!< tool-tip display time (seconds that tip is showsn for).
  323.         float       d_fadeTime;     //!< tool-tip fade time (seconds it takes for tip to fade in and/or out).
  324.  
  325.     private:
  326.         /*************************************************************************
  327.             Static Properties for this class
  328.         *************************************************************************/
  329.         static TooltipProperties::HoverTime      d_hoverTimeProperty;
  330.         static TooltipProperties::DisplayTime    d_displayTimeProperty;
  331.         static TooltipProperties::FadeTime       d_fadeTimeProperty;
  332.  
  333.         /*************************************************************************
  334.             Private methods
  335.         *************************************************************************/
  336.         void addTooltipProperties(void);
  337.     };
  338.  
  339. } // End of  CEGUI namespace section
  340.  
  341.  
  342. #if defined(_MSC_VER)
  343. #    pragma warning(pop)
  344. #endif
  345.  
  346. #endif  // end of guard _CEGUITooltip_h_
  347.